/**
 * Created by yihua on 2017/3/5.
 */
/**
 * Created by yihua on 2017/3/5.
 */
$(document).ready(function () {

    $(".ordership").each(function () {
        $(this).unbind('click').click(function () {
            $("#ordershipModal").modal('show')
            var orderid = $(this).parent()[0].id
            console.log('订单ID：', orderid)
            $("#shipping_confirm").unbind('click').click(function () {
                var options = {
                    url: '/home/order/ordership',
                    beforeSubmit: validate,  // pre-submit callback
                    success: showResponse,  // post-submit callback
                    dataType: 'json',
                    type: 'post',
                    data: {
                        'order_id': orderid,
                    }
                };
                $("#editshipForm").ajaxSubmit(options);
            });

            function validate(formData) {
                for (var i = 0; i < formData.length; i++) {
                    if (!formData[i].value) {
                        toastr.error('请输入所有选项', '', {positionClass: 'toast-bottom-center'});
                        return false;
                    }
                }
            }

            function showResponse(responseText) {
                if (0 !== responseText.errno) {
                    toastr.error(responseText.errmsg, '', {positionClass: 'toast-bottom-center'});
                }
                else {
                    toastr.success('增加成功', '', {positionClass: 'toast-bottom-center'});
                    $('#ordershipModal').modal('hide');
                    window.location.reload();
                }
            }
        });
    });

});
